package calc;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        try {
            ServerSocket s = new ServerSocket(8189);
            Socket incoming = s.accept();
            try {

                InputStream inStream = incoming.getInputStream();
                OutputStream outStream = incoming.getOutputStream();
                Scanner in = new Scanner(inStream);
                PrintWriter out = new PrintWriter(outStream, true);
                out.println("Hello, netWorld, motherfucker!");
                boolean done = false;
                while (in.hasNextLine() && !done) {
                    String line = in.nextLine();
                    System.out.println("ECHO:" + line);
                    out.println(line);
                    if (line.trim().equals("BYE")) {
                        done = true;
                    }
                }
            } finally {
                s.close();
            }
        } catch (Exception e) {
        }

    }
}